<div ng-controller="articlePopoverCtrl">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal">
			<span>&times;</span>
			<span class="sr-only">Close</span>
		</button>
		<h4 class="modal-title">${typeName}</h4>
	</div>
	<div class="modal-body" max-height="-95" lazy="search()">
		<div waterfall data="articles" as="art" ng-if="'${type}'==='02'">
			<div class="fade-animate waterfall-elem" ng-click="select(art)" ng-class="selectedClass(art)" article="art"></div>
		</div>
		<div waterfall data="articles" as="art" num="4" ng-if="'${type}'==='03'">
			<div class="fade-animate waterfall-elem" ng-click="select(art)" ng-class="selectedClass(art)" article-multi="art"></div>
		</div>
	</div>
	<div class="modal-footer">
		<button type="button" class="btn btn-success" ng-click="${callback}(selected)" ng-disabled="btnDisabled()" data-dismiss="modal">&{'resource.button.select.article'}</button>
		<button type="button" class="btn btn-default" data-dismiss="modal">&{'app.common.button.cancel'}</button>
	</div>
</div>

<script type="text/javascript">
'use strict'
var articlePopoverCtrl = ['$scope', '$http', function($scope, $http) {
	// 定义方法
	angular.extend($scope, {
		init: function() {
			$scope.selected = undefined;
		}, btnDisabled: function() {
			return angular.isUndefined($scope.selected);
		}, search: function() {
			// 初始化当前页号
			if (angular.isUndefined($scope.articles_current)) $scope.articles_current = 1;
			
			// 仅当总页数为空或小于等于当前页数时进行加载数据
			if (angular.isUndefined($scope.articles_total) || $scope.articles_total >= $scope.articles_current) {
				$http({
					method: 'post',
					url: (function() {
						if ('${type}' === '02') {
							return '@{Resources.article_search}';
						} else if ('${type}' === '03') {
							return '@{Resources.article_multi_search}';
						}
						return '';
					})(),
					data: jQuery.param({page: $scope.articles_current, size: 20}),
					headers: {'Content-Type': 'application/x-www-form-urlencoded'}
				}).success(function(data) {
					$scope.articles = data.content;
					$scope.articles_total = data.totalPage;
					$scope.articles_current = $scope.articles_current + 1;
				});
			}
		}, selectedClass: function(article) {
			return (!angular.isUndefined(article) && $scope.selected === article) ? 'active' : '';
		}, select: function(article) {
			$scope.selected = ($scope.selected === article) ? undefined : article;
		}
	});
	
	// 初始化
	$scope.init();
}];
</script>
